package com.service.impl;

import com.entity.MeishiEntity;
import com.entity.view.MeishiView;
import com.service.RecommendationService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;
import java.util.stream.Collectors;

@SpringBootTest
public class RecommendationServiceImplTest {

    @Autowired
    private RecommendationService recommendationService;

    @Test
    public void testGetHotMeishiByCollection() {
        List<MeishiEntity> hotList = recommendationService.getHotMeishiByCollection();
        // 打印结果
        System.out.println("热门美食ID顺序：");
        for (MeishiEntity entity : hotList) {
            System.out.println(entity.getId());
        }
        // 断言第一个是14（收藏最多）
        Assertions.assertEquals(14, hotList.get(0).getId());
        // 断言前4个包含5、6、12（顺序可任意）
        List<Integer> top4 = hotList.subList(1, 4).stream().map(MeishiEntity::getId).collect(Collectors.toList());
        Assertions.assertTrue(top4.contains(5));
        Assertions.assertTrue(top4.contains(6));
        Assertions.assertTrue(top4.contains(12));
    }

    @Test
    public void testGetUserBasedRecommendations() {
        String userId = "1"; // 请替换为实际存在的用户ID
        int limit = 5;
        List<String> recommendIds = recommendationService.getUserBasedRecommendations(userId, limit);
        System.out.println("推荐美食ID列表：" + recommendIds);
        assert recommendIds.size() <= limit;
    }

    @Test
    public void testGetUserBasedRecommendationViews() {
        String userId = "1";
        int limit = 5;
        if (recommendationService instanceof RecommendationServiceImpl) {
            List<MeishiView> recommendList = ((RecommendationServiceImpl)recommendationService)
                    .getUserBasedRecommendationViews(userId, 1, limit);
            System.out.println("推荐美食详情列表：" + recommendList);
            assert recommendList.size() <= limit;
        }
    }
} 